import java.io.*;
import java.util.*;

public class B {

    BufferedReader fin;
    PrintWriter fout;

    void openFiles() throws IOException {
        fin = new BufferedReader(new FileReader("B.in"));
        fout = new PrintWriter(new BufferedWriter(new FileWriter("B.out")));
    }

    void closeFiles() throws IOException {
        fin.close();
        fout.close();
    }

    int T, H, W;
    int[][] a;
    char[][] c;
    int[] dx = {-1, 0, 0, 1}, dy = {0, -1, 1, 0};
    boolean[][] fre;
    
    void input() throws IOException {
    	String s = fin.readLine();
    	T = Integer.parseInt(s);
    }

    boolean inside(int x, int y)
    {
    	return ((0 <= x) && (x < H) && (0 <= y) && (y < W));
    }
    
    void BFS(int x, int y, char b)
    {
    	int dir = 4, min = 1000000000;
    	for (int i = 0; i < 4; i++)
    		if ( (inside(x+dx[i], y+dy[i])) && (min > a[x+dx[i]] [y+dy[i]]) )
    		{
    			min = a[x+dx[i]] [y+dy[i]];
    			dir = i;
    		}
    	
		fre[x][y] = false;
    	if (min >= a[x][y]) c[x][y] = b;
    	else
    	{
    		if (c[x + dx[dir]][y + dy[dir]] == 'A')	BFS(x+dx[dir], y+dy[dir], b);
			c[x][y] = c[x+dx[dir]][y+dy[dir]];
    	}
    }
    
    void solve()
    {
    	c = new char[H][W];
    	for (int i = 0; i < H; i++)
    		for (int j = 0; j < W; j++) c[i][j] = 'A';
    	
    	fre = new boolean[H][W];
    	for (int i = 0; i < H; i++)
    		for (int j = 0; j < W; j++) fre[i][j] = true;
    	
    	char basin = 'a';
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
    		    if (fre[i][j])
    			{
    				BFS(i, j, basin);
    				if (c[i][j] == basin) basin += 1;
    			}
    }
    
    void process() throws IOException {
    	for (int i = 0; i < T; i++)
    	{
    		String s = fin.readLine();
    		StringTokenizer ss = new StringTokenizer(s);
    		H = Integer.parseInt(ss.nextToken());
    		W = Integer.parseInt(ss.nextToken());
    		
    		a = new int[H][W];
    		for (int j = 0; j < H; j++)
    		{
    			s = fin.readLine();
    			ss = new StringTokenizer(s);
    			for (int k = 0; k < W; k++)
    				a[j][k] = Integer.parseInt(ss.nextToken());
    		}
    		
    		solve();
    		output(i+1);
    	}
    }

    void output(int k) {
		fout.println("Case #" + k + ":");
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++) fout.print(c[i][j] + " ");
			fout.println();
		}
    }

    public static void main(String[] args) throws IOException {
        B myProgram = new B();

        myProgram.openFiles();
        myProgram.input();
        myProgram.process();
        myProgram.closeFiles();
    }
	}
